package Gather;

import java.util.Date;

/**
 * Created by dycong on 2017/3/1.
 */
public class testInstance {



//    public static void main(String[] args) {

    public  void main(String[] args) {
        boolean b1 = "String" instanceof Object;
        boolean b2 = new String() instanceof String;
        boolean b3 = new Object() instanceof String;

        /*编译不通过，'A'基本类型，不是对象*/
//        boolean b4='A' instanceof String;

        /*instanceof特有规则：左为null直接返回false，不管右是什么。--->不需要判空!!*/
        boolean b5 = null instanceof String;

        boolean b6 = (String) null instanceof String;

        /*编译不通过，没有继承或实现关系*/
//        boolean b7=new Date() instanceof String;

        /*编译通过，返回false，orDateInstanceof(T t)传入的t表面是Object，实质是String*/
        boolean b8 = new genericClass<String>().orDateInstanceof("");
    }

    class genericClass<T> {
        public boolean orDateInstanceof(T t) {
            return t instanceof Date;/*t instanceof Date泛型t效果类似于Object instanceof Date*/
        }
    }
}
